package com.firewolf.rocketmq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

/**
 * 作者：刘兴 时间:2019-07-11
 * 单向生产者，不关心投递的结果
 **/
public class OneWayProducer {

  public static void main(String[] args) throws Exception {
    DefaultMQProducer producer = new
        DefaultMQProducer("producer-group1");
    producer.setNamesrvAddr("10.211.55.6:9876");
    producer.start();
    for (int i = 0; i < 5; i++) {
      //创建要发送的消息对象
      Message msg = new Message("mytopic" /* Topic */,
          "TagA" /* Tag */,
          ("OneWay Message " +
              i).getBytes("UTF-8") /* Message body */
      );
      //发送消息
      producer.sendOneway(msg);
    }
    //关闭生产者
    producer.shutdown();
  }

}
